<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta content="IE=edge" http-equiv="X-UA-Compatible">
    <meta content="width=device-width, initial-scale=1, shrink-to-fit=no" name="viewport">
    <meta content="featon inc." name="author">
    <link href="/static/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link href="/static/vendor/bootstrap/css/bootstrap-theme.min.css" rel="stylesheet">
    <link href="/static/vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet">
    <link href="/static/vendor/skin/ftskin.css" rel="stylesheet">
    <link href="/static/vendor/webuploader/webuploader.css" rel="stylesheet" type="text/css">
    <link href="/static/vendor/datetimepicker/jquery.datetimepicker.css" rel="stylesheet">
    <title>单位基本信息</title>
</head>

<body style="padding-top: 30px; padding-left: 30px">
<div class="ft-subpage-wrapper container-fluid">
    <form action="#" id="form1" method="post" name="form1">
        <div class="row">
            <div class="col-lg-12" id="form_table">
                <fieldset>
                    <legend id="titleText">--</legend>
                    <table cellpadding="0" cellspacing="0" class="form-table form-table-border" id="">
                        <tr>
                            <th><span class="f_red">*</span>企业名称</th>
                            <td colspan="2">
                                <input class="form-control" readonly id="name" name="name" placeholder="" type="text">
                                <span class="cError"></span>
                            </td>
                        </tr>
                        <tr>
                            <th><span class="f_red">*</span>相关证件</th>
                            <td>
                                <select class="form-control" disabled id="zjType" name="zjType">
                                    <option disabled selected>--请选择--</option>
                                    <option>营业执照</option>
                                    <option>身份证</option>
                                    <option>其他证件</option>
                                </select>
                                <span class="cError"></span>
                            </td>
                            <td>
                                <input class="form-control" readonly id="yyCode" name="yyCode" placeholder="证件号码"
                                       type="text">
                                <span class="cError"></span>
                            </td>
                        </tr>
                        <tr>
                            <th><span class="f_red">*</span>企业类型</th>
                            <td colspan="2">
                                <select class="form-control" disabled readonly id="companyType" name="companyType"
                                        style="width:300px">
                                    <option id="companyType_val" disabled selected>--请选择--</option>
                                </select>
                                <span class="cError"></span>
                            </td>
                        </tr>

                        <tr>
                            <th><span class="f_red">*</span>法人（负责人）</th>
                            <td colspan="2">
                                <input readonly class="form-control" id="legalMan" name="legalMan"
                                       placeholder="法人（负责人）姓名"
                                       type="text">
                                <span class="cError"></span>
                            </td>
                        </tr>
                        <tr>
                            <th><span class="f_red">*</span>联系电话</th>
                            <td colspan="2">
                                <input readonly class="form-control" id="phone" name="phone" placeholder="联系电话"
                                       type="tel">
                                <span class="cError"></span>
                            </td>
                        </tr>

                        <tr>
                            <th>
                                <span class="f_red">*</span>区县
                            </th>
                            <td>
                                <select disabled class="form-control dq" id="dq3Id" name="dq3Id">
                                    <option id="dq3Id_val" disabled selected>--请选择--</option>
                                </select>
                            </td>
                            <td>
                                <select disabled class="form-control dq" id="dq4Id" name="dq4Id">
                                    <option id="dq4Id_val" disabled selected>--请选择--</option>
                                </select>
                            </td>
                        </tr>

                        <tr>
                            <th><span class="f_red">*</span>详细地址</th>
                            <td colspan="2">
                                <input readonly class="form-control" id="address" name="address" placeholder="详细地址"
                                       type="text">
                            </td>
                        </tr>

                        <tr>
                            <th>备注</th>
                            <td colspan="2">
                                <textarea readonly style="resize: none;" class="form-control" id="remark" name="remark"
                                          rows="2"></textarea>
                            </td>
                        </tr>

                    </table>
                </fieldset>
                <div class="bottom-tools-box">
                    <button onclick="is_modify(1)" class="btn btn-warning" id="modify" type="button"><span
                            aria-hidden="true" class="glyphicon glyphicon-floppy-disk"></span> 修改
                    </button>
                    <button onclick="addAndUpdateObject()" style="display: none" class="btn btn-info" id="save_but"
                            type="button"><span
                            aria-hidden="true" class="glyphicon  glyphicon-ok"></span> 提交
                    </button>
                    <button onclick="is_modify(2)" style="display: none" class="btn btn-info" id="cancel" type="button"><span
                            aria-hidden="true" class="glyphicon  glyphicon-remove"></span> 取消
                    </button>
                </div>

            </div>
        </div>
    </form>
</div>
<input type="hidden" th:value="${code}" id="code">
<script src="/static/vendor/jquery/jquery-3.3.1.min.js"></script>
<script src="/static/vendor/bootstrap/js/bootstrap.min.js"></script>
<script src="/static/vendor/validate/jquery.validate.min.js" type="text/javascript"></script>
<script src="/static/vendor/webuploader/webuploader.js" type="text/javascript"></script>
<script src="/static/vendor/skin/js/ft-ui.js"></script>
<script src="/static/vendor/skin/js/jquery.c.js"></script>
<script src="/static/vendor/skin/js/java.js"></script>
<script src="/static/vendor/skin/js/upload-util.js"></script>
<script src="/static/vendor/sortable/sortable.js"></script>
<script src="/static/vendor/datetimepicker/jquery.datetimepicker.js"></script>
<script>
    function iniInfoForm() {
        var validator = $("#form1").validate({
            debug: true,
            rules: {
                // user_realname: {
                //     required: true
                // },
                // dq_yw_name: {
                //     required: true
                // }
            },
            messages: {
                // user_realname: {
                //     required: "执法人员不能为空！"
                // },
                // dq_yw_name: {
                //     required: "所属地区不能为空"
                // }
            },
            errorPlacement: function (error, element) {
                error.appendTo(element.parents('td').find(".cError"));
            },
            submitHandler: function (form) {
            }
        });
    }

    let $qyid = $("#code").val();
    $(function () {
        if ($qyid !== null && $qyid !== '') {
            $.post("/ci/getCompanyByIdOrNameOrCode?code=" + $qyid, function (result) {
                console.log(result)
                $("#name").val(result.name);
                $("#zjType").val(result.zjType);
                $("#yyCode").val(result.yyCode);
                $("#companyType_val").text(result.companyType);
                $("#legalMan").val(result.legalMan);
                $("#phone").val(result.phone);
                $("#dq3Id_val").text(result.dq3Id);
                $("#dq4Id_val").text(result.dq4Id);
                $("#address").val(result.address);
                $("#remark").val(result.remark);
            })
        }
    })

    var is_submit = false;
    let url = '';
    if ($qyid === null || $qyid === '') {
        url = '/ci/addCompany';
    } else {
        url = '/ci/updateCompany';
    }

    function is_modify(val) {
        if (val === 1) {
            $("#name").focus();
            $("#save_but,#cancel").show();
            $("form input,form select,form textarea").removeAttr("disabled").removeAttr("readonly");
            $("#modify").hide();
        } else {
            $("#save_but,#cancel").hide();
            $("form input,form textarea").attr("readonly", "true");
            $("form select").attr("disabled", "true");
            $("#modify").show();
        }
    }

    function addAndUpdateObject() {
        let bean = {
            qyId: $("#qyId").val(),
            name: $("#name").val(),
            zjType: $("#zjType").val(),
            yyCode: $("#yyCode").val(),
            companyType: $("#companyType").val(),
            legalMan: $("#legalMan").val(),
            phone: $("#phone").val(),
            dq3Id: $("#dq3Id").val(),
            dq4Id: $("#dq4Id").val(),
            address: $("#address").val(),
            remark: $("#remark").val()
        }
        if (top.ajax.synclBody(url, bean)) {
            modelWindow.alert(top.CMSLang.Add_success);
            $("#save_but,#cancel").hide();
            $("form input,form textarea").attr("readonly", "true");
            $("form select").attr("disabled", "true");
            $("#modify").show();
            top.getCurrentFrameObj().loadListble();
            top.tab_colseOnclick();
        }
    }

    $(".dq").click(function () {
        let $that = $(this);
        let thisId = $($that).attr('id');
        let area = '610300000000';
        let $dq3Id = $("#dq3Id");
        $("#dq3Id_val").hide();
        if (thisId === 'dq4Id') {
            let subArea = $dq3Id.val()
            if (subArea !== '' || subArea !== null) {
                area = subArea;
            }
        } else {
            $("#dq4Id").empty().append(`
                    <option disabled selected>--请选择--</option>
                `);
        }

        let url = '/diqu/getChildDiquList/' + area;
        let children = $($that).children();
        if (children.length <= 1) {
            $.get(url, function (result) {
                console.log(result)
                result.forEach((item) => {
                    $($that).append(`
                    <option  value=` + item.dq_id + `>` + item.dq_name + `</option>
                `)
                })
            })
        }
    })


</script>
</body>

</html>
